package br.com.monografia.adapter;

import java.util.List;

import br.com.monografia.R;
import br.com.monografia.model.Alimento;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AlimentoListAdapter extends BaseAdapter{
	
	private LayoutInflater inflater;
	private List<Alimento> lista;
	
	public AlimentoListAdapter(Context ctx, List<Alimento> lista) throws Exception{
		inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.lista = lista;
	}

   public int getCount() {
	 return lista.size();  	
   }
   
   
   public Object getItem(int position) {
	   return lista.get(position);
   }
   
   public long getItemId(int position) {
	return position;
   }   
   
   public View getView(int position, View convertView, ViewGroup parent) {
	   Alimento alimento = lista.get(position);
	   View view = inflater.inflate(R.layout.alimento_linha_tabela, null);
	  
	   TextView descricao = (TextView) view.findViewById(R.id.descricao);
	   descricao.setText(alimento.getDescricao());
	   
	   TextView medida = (TextView) view.findViewById(R.id.medida);
	   medida.setText(alimento.getMedida());
	   
	   TextView peso = (TextView) view.findViewById(R.id.peso);
	   peso.setText(alimento.getPeso()+"");
	   
	   TextView carboidrato = (TextView) view.findViewById(R.id.carboidrato);
	   carboidrato.setText(alimento.getCarboidrato()+"");
	   

	   return view;
	   
   }
	
}
